<?php
$this->breadcrumbs=array(
	'购物车',
);

Yii::app()->clientScript->registerCoreScript('jquery');
Yii::app()->clientScript->registerCoreScript(Yii::app()->homeUrl.'/js/common.js');
Yii::app()->clientScript->registerCssFile(Yii::app()->homeUrl.'/css/style/style_cart.css');
Yii::app()->clientScript->registerCssFile(Yii::app()->homeUrl.'/css/style/style_two.css');
?>
<script type="text/javascript">
    $(document).ready(function() {
        /*
         * 批量删除 
         */
        $("#deletesCart").click(function (event) {
            $('#cartForm').submit(); 
        });

    });
/*
 * 增产品库存
 * id 
 * rowid
 * t  类型
 */
function carminus(id,rowid,t){
    var t = t|1;
    var qty = parseInt($("#"+id).val());
    if( t == 1 ){
        qty++;                
    }else if(t == -1){
        qty--;                
    }else{
        qty = qty;
    }
    //alert(qty);                     
    $.ajax({
        type:"POST",
        url: "<?php echo Yii::app()->createUrl('/cart/Qty') ?>",
        data:"rowid="+rowid+"&qty="+qty,
        success: function(msg){
            //alert(msg);        
            if(msg==1){
                alert('库存不足!');
                location.reload();              
            }else{
                location.reload();            
            }
            
        }
    })
};
function deletes(rowid,pid){
    if(pid==1){
        alert('您确定要删除此套餐?如果删除此套餐,套餐内的相关产品也会删除!');       
    }else{
        alert('您确定要删除此产品?');        
    }
    $.ajax({
        type:"POST",
        url: "<?php echo Yii::app()->createUrl('/cart/Delete') ?>",
        data:"rowid="+rowid,
        success: function(data){                            
            if(data ==0){
                $('#'+rowid).hide();
            }else{                
                json = eval(data)   
                for(var i=0; i<json.length; i++)   
                {   
                    $('#'+json[i]).hide();  
                }
            }               
        }
    })
};
</script>
<div class="steps">
        <ul class="fs_14 fw_b c_666 c_f">
            <li class="cur first"><span class="one">1.查看购物车</span></li>
            <li class=""><span class="two">2.确认订单信息</span></li>
            <li class=""><span class="three">3.付款</span></li>
            <li class=""><span class="four">4.确认收货</span></li>
            <li class="last"><span class="five">5.评价</span></li>
        </ul>
    </div>
    <div class="hr_25"></div>
    <?php echo CHtml::beginForm(array('/cart/Deletes'), 'POST', array('id'=>'cartForm')) ?>
    <div class="selected_pro">
        <div class="hd">
            <ul class="c_f">
                <li class="a"><input class="chk" type="checkbox" onclick="CheckAll('chekall','rowid[]')" name="chekall" />全选</li>
                <li class="b">商品名称</li>
                <li class="c">单价(元)</li>
                <li class="d">数量</li>
                <li class="e">优惠</li>
                <li class="f">小计(元)</li>
                <li class="g">操作</li>
            </ul>
        </div>
        <div class="hr_18"></div>
        <table class="order_table" width="100%" cellspacing="0" cellpadding="0">
            <!-- <tr class="shop">
                <td colspan="7"><input class="chk" type="checkbox" name="" />店铺：<a class="c_06c" href="javascript:" title="">家猫商城</a><a class="ico_qq qq_online2" href="javascript:" title="和我联系">和我联系</a></td>
            </tr> -->
              <?php
            //print_r($mycart);
            if(count($mycart) > 0){
                $i=1;                
            foreach( (array)$mycart as $m){?>
            <tr id="<?php echo $m['rowid'] ?>">
                <td class="check" width="5%"><?php echo CHtml::hiddenField($i.'[rowid]', $m['rowid']) ?><?php echo CHtml::checkBox('rowid[]',false,array('class'=>'chk','value'=>$m['rowid'])) ?></td>
                <td class="pro">
                    <div class="c_img c_img60"><?php echo Tool::thumb($m['pic_url'],50,50,$m['title']) ?></div>
                    <p class="title_pro"><?php echo Chtml::link($m['title'],array('home/product/detail/','id'=>$m['id']),array( 'calss'=> 'c_666' ,'title'=>$m['title'],'target'=>'_black')) ?></p>
                    <p class="other c_666">
                        <?php foreach( (array)$m['options'] as $key=>$val){ ?>
                        <span><?php echo $val?></span>
                        <?php }?>
                    </p>
                </td>
                <td class="price fs_14" width="12%"><del class="c_999 d_b"><?php echo $m['saleprice'] ?></del><span><?php echo $m['price'] ?></span></td>
                <td class="amount" width="14%">
                    <?php if($m['package']){ ?>
                            <span><?php echo $m['qty'] ?></span>
                    <?php }else{ ?>
                    <a class="ico minus" href="javascript:" onclick="carminus('<?php echo $i.'_qty'?>','<?php echo $m['rowid']?>',-1)"></a><?php echo CHtml::textField($i.'[qty]', $m['qty'], array('size' => '4', 'maxlength' => '5','class'=>'t_ipt ipt_bg','onchange'=>'carminus(\''.$i.'_qty\',\''.$m['rowid'].'\',2)')) ?><a class="ico plus" href="javascript:"  onclick="carminus('<?php echo $i.'_qty'?>','<?php echo $m['rowid']?>',1)"></a>
                    <?php } ?>
                </td>
                <td class="agio" width="12%">
                    <span>
                    <?php echo OrdDiscount::model()->getDiscountType($m['active']);?>
                    </span>
                </td>
                <td class="integral" width="11%"><span class="fw_b fs_14 c_666"><?php echo $m['subtotal'] ?></span></td>
                <td class="operate" width="11%">
                    <?php 
                    if($m['package']){
                        echo CHtml::link('删除', 'javascript:',array('class'=>'c_666','onclick'=>'deletes(\''.$m['rowid'].'\',1)'));
                    }else{
                        echo CHtml::link('删除', 'javascript:',array('class'=>'c_666','onclick'=>'deletes(\''.$m['rowid'].'\')'));
                    }?>                    
                </td>
            </tr>           
            <?php 
            $i++;
            }
            
            }else{ ?>
            <tr>
             <td colspan="7" height="50" class="c_red">购物车为空！<?php echo CHtml::link('去购物', array('/index.php'), array('class'=>'c_06c','title'=>'去购物'))?></td>
            </tr>
          <?php } ?>
        </table>
        <div class="hr_12"></div>
        <div class="total_info c_f">
            <div class="info_l f_l"><input class="chk" type="checkbox" onclick="CheckAll('chekall','rowid[]')" name="chekall" />全选<a class="btn btn_del" href="javascript:" id="deletesCart"  title="删除选中商品">删除选中商品</a><?php echo CHtml::link('清空购物车', array('/cart/destory'), array('class'=>'btn btn_del'))?></div>
            <div class="info_r f_r"><span class="total_price">商品总价（不含运费）：<em class="ff_yh c_f60 fs_22"><?php echo $total ?></em> 元</span><?php echo CHtml::link('去结算', array('/member/order/confirm_order'), array('class'=>'btn btn_settle'))?></div>
        </div>  
    </div>
   <?php echo CHtml::endForm(); ?>
    <div class="hr_30"></div>
    <!--购买过此商品的还购了 start-->
    <div class="else_pro">
        <div class="hd"><h2 class="fs_14">购买过此商品的还购了...</h2></div>
        <div class="bd pro_list">
            <ul class="c_f">
                 <?php                   
                    $sql = new CDbCriteria(array(
                                'condition' => 'zp_status = 2 AND zp_state = 2',
                                'order'=>'RAND()',
                                'limit' => '6'
                            ));
                    $items = Product::model()->findAll($sql);
                    if ($items) {                        
                        foreach ($items as $i) {
                            ?>
                            <li class="item">
                                <div class="c_img c_img120"><?php echo CHtml::link( Tool::thumb( $i->zp_pic,120,120,$i->zp_name ),array('/home/product/detail/', 'id'=>$i->zp_id ),array('target'=>'_blank','title'=>$i->zp_name) ) ?></div>
                                <p class="price ff_yh"><strong class="c_orange fs_15">&yen;<?php echo $i->zp_price ?></strong></p>
                                <p class="title"><?php echo $i->getTitle() ?></p>
                                <p class="buy"><?php echo CHtml::link('点击购买',array('/home/product/detail/', 'id'=>$i->zp_id ),array('target'=>'_blank','title'=>$i->zp_name,'class'=>'btn btn_buy'))?></p>
                            </li>                                            
                            <?php
                        }
                        
                    } else {
                    ?>
                        <p style="text-align:center">没有找到商品!</p>
                <?php } ?>
            </ul>
        </div>
    </div>
    <!--购买过此商品的还购了 end-->